package cn.wolfcode.rbac.service.impl;

import cn.wolfcode.rbac.domain.CustomerTraceHistory;
import cn.wolfcode.rbac.mapper.CustomerTraceHistoryMapper;
import cn.wolfcode.rbac.query.QueryObject;
import cn.wolfcode.rbac.service.ICustomerTraceHistoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerTraceHistoryServiceImpl implements ICustomerTraceHistoryService {

    @Autowired
    private CustomerTraceHistoryMapper mapper;

    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<CustomerTraceHistory> list = mapper.selectCustomerTraceHistory(qo);
        for(CustomerTraceHistory cth:list){
            if(cth.getType()==0){
                cth.setDisplayType("潜在客户开发");
            }else{
                cth.setDisplayType("正式客户跟进");
            }
            switch (cth.getTraceResult()){
                case 1:
                    cth.setDisplayTraceResult("差");
                    continue;
                case 2:
                    cth.setDisplayTraceResult("中");
                    continue;
                case 3:
                    cth.setDisplayTraceResult("优");
                    continue;
                default:
                    cth.setDisplayTraceResult("");
                    continue;
            }
        }
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(CustomerTraceHistory cth) {
        if(cth.getId()!=null){
            this.mapper.update(cth);
        }else{
            System.out.println(cth);
            this.mapper.insert(cth);
        }
    }
}
